package com.develop.service;

import java.util.LinkedList;
import java.util.List;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.develop.BeanUtils.AlarmInfo;
import com.develop.dao.AlarmDao;

import net.sf.json.JSONObject;

@Component
public class AlarmConsumer {
	@Autowired
	private AlarmDao AlarmDao;

	public void saveAlarm(List<ConsumerRecord<String, String>> records) {
		LinkedList<AlarmInfo> alarmList = new LinkedList<AlarmInfo>();
		JSONObject jsonobject = null;
		AlarmInfo alarm = null;
		for (int i = 0; i < records.size(); i++) {
			jsonobject = JSONObject.fromObject(records.get(i).value());

			alarm = (AlarmInfo) JSONObject.toBean(jsonobject, AlarmInfo.class);
			alarmList.add(alarm);
		}

		AlarmDao.batchSaveAlarmInfo(alarmList);
	}
}